//package com.maikang.exammall.configuration;
//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.domain.AuditorAware;
//import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.context.SecurityContextHolder;
//
//import java.util.Optional;
//import static java.util.Optional.ofNullable;
//
//@Configuration
//@EnableJpaAuditing(auditorAwareRef = "auditorAware")
//public class JpaConfiguration {
//
//    @Bean("auditorAware")
//    AuditorAware<Long> AuditorAware() {
//        return new AuditorAwareImpl();
//    }
//
//    public static class AuditorAwareImpl implements AuditorAware<Long> {
//
//        @Override
//        public Optional<Long> getCurrentAuditor() {
//            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//            Object principal = authentication.getPrincipal();
//            Long userId = 0L;
//            if (principal != null) {
//                userId = (Long) principal;
//            }
//            return Optional.ofNullable(userId);
//        }
//    }
//}
